<?php
/**
* @author: Truong Kim Phung
* @date: Friday, January 24, 2014
*/

/**
* Not login
* Not permission
*
* Note: only root, administrator, leader with permission admin module
*/
if( !isset($AppUI) || 
	!isset($_SESSION['category'])
) {
	redirect(HOST_BACKEND);
}
$this->load->model('category_model', 'category');	
$intTotal   = 0;
$intPage    = $this->input->get('page', 1);
$intType    = $this->input->get('type', 0);
$intStatus  = $this->input->get('stt', -1);
$strStart   = $this->input->get('startdate', '');
$strEnd     = $this->input->get('enddate', '');
$intCancel	= $this->input->get('pcancel', 0);
$intLimit   = 20;
$intOffset  = ($intPage-1)*$intLimit;

if($strStart != '' || $strEnd != '') {
	$_SESSION['CATEGORY_CANCEL'] 	= 1;	
	$_SESSION['CATEGORY_SEARCH']	= $this->input->get();
}
else {
	if(isset($_SESSION['CATEGORY_SEARCH'])) unset($_SESSION['CATEGORY_SEARCH']);
	if(isset($_SESSION['CATEGORY_CANCEL'])) unset($_SESSION['CATEGORY_CANCEL']);
    $strStart = '';
    $strEnd = '';
}
if($intCancel) {
	if(isset($_SESSION['CATEGORY_SEARCH'])) unset($_SESSION['CATEGORY_SEARCH']);
	if(isset($_SESSION['CATEGORY_CANCEL'])) unset($_SESSION['CATEGORY_CANCEL']);
    $strStart = '';
    $strEnd = '';
}

$arrResult	= $this->category->getAll($AppUI->type, $intType, $intStatus, CI_Function::convertStrToDate($strStart),
											CI_Function::convertStrToDate($strEnd), $intOffset, $intLimit, $intTotal);
$this->smarty->assign('arrResult',  $arrResult);
$this->smarty->assign('intTotal',   $intTotal);
$this->smarty->assign('intOffset',  $intOffset);
$this->smarty->assign('intLimit',   $intLimit);
$this->smarty->display('category/index.tpl');